//
//  BleControlInfoCell.m
//  StormWatch
//
//  Created by 王岩 on 2024/8/31.
//

#import "BleControlInfoCell.h"

@implementation BleControlInfoCell
- (IBAction)clickDisconnectBle:(id)sender {
    
    self.disBlock();
    
}

- (void)refreshUI {
    self.eleLab.text = [NSString stringWithFormat:@"%ld%%",[StormCommandTool sharedInstance].electric];
    
    if ([StormCommandTool sharedInstance].electric < 25) {
        self.eleImageView.image = S_imageNamed(@"battery_low");
    }else if ([StormCommandTool sharedInstance].electric >= 25 && [StormCommandTool sharedInstance].electric < 35) {
        self.eleImageView.image = S_imageNamed(@"battery_25");
    }else if ([StormCommandTool sharedInstance].electric >= 35 && [StormCommandTool sharedInstance].electric < 45) {
        self.eleImageView.image = S_imageNamed(@"battery_35");
    }else if ([StormCommandTool sharedInstance].electric >= 45 && [StormCommandTool sharedInstance].electric < 55) {
        self.eleImageView.image = S_imageNamed(@"battery_45");
    }else if ([StormCommandTool sharedInstance].electric >= 55 && [StormCommandTool sharedInstance].electric < 65) {
        self.eleImageView.image = S_imageNamed(@"battery_55");
    }else if ([StormCommandTool sharedInstance].electric >= 65 && [StormCommandTool sharedInstance].electric < 75) {
        self.eleImageView.image = S_imageNamed(@"battery_65");
    }else if ([StormCommandTool sharedInstance].electric >=75 && [StormCommandTool sharedInstance].electric < 85) {
        self.eleImageView.image = S_imageNamed(@"battery_75");
    }else if ([StormCommandTool sharedInstance].electric >=85 && [StormCommandTool sharedInstance].electric < 100) {
        self.eleImageView.image = S_imageNamed(@"battery_85");
    }else if ([StormCommandTool sharedInstance].electric >= 100 ) {
        self.eleImageView.image = S_imageNamed(@"battery_100");
    }
}

- (void)awakeFromNib {
    [super awakeFromNib];
    
    self.stateLab.text = SWString(@"Connected");
    [self.cancelBtn setTitle:SWString(@"Remove Device") forState:0];
    
    self.cancelBtn.layer.cornerRadius = 4;
    
    NSMutableArray * arr = [[NSMutableArray alloc] init];
    NSString * address = [FRQBluetoothManager shareManager].curPeripheral.macAddress;
    
    if (address.length) {
        for (int i = 0 ; i < 6; i ++) {
            [arr insertObject:[address substringWithRange:NSMakeRange(i * 2, 2)] atIndex:0];
        }
        self.macAddress.text = [arr componentsJoinedByString:@":"];
    }else {
        self.macAddress.text = @"----";
    }
  
    // Initialization code
}

@end
